import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:flutter_svg/svg.dart';

import '../../../constants.dart';
import '../../../theme.dart';
import 'logic.dart';

class MainDiscoverPage extends StatelessWidget {
  MainDiscoverPage({Key? key}) : super(key: key);

  final logic = Get.put(MainDiscoverLogic());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: AppColor.colorBackground,
      appBar: AppBar(
        title: const Text('发现'),
      ),
      body: ListView(
        children: [
          _buildCard(
            Column(
              children: [
                _buildItem(
                  'assets/icons/ic_dis_pay.png',
                  '收款',
                  () => logic.toOrderIncome(),
                  BorderRadius.only(
                    topLeft: Radius.circular(kRadiusSmall),
                    topRight: Radius.circular(kRadiusSmall),
                  ),
                ),
                _buildItem(
                  'assets/icons/ic_dis_receipt.png',
                  '付款',
                  () => logic.toOrderPaid(),
                  BorderRadius.only(
                    bottomLeft: Radius.circular(kRadiusSmall),
                    bottomRight: Radius.circular(kRadiusSmall),
                  ),
                ),
              ],
            ),
          ),
          _buildCard(Column(
            children: [
              _buildItem(
                'assets/icons/ic_dis_notice.png',
                '案源',
                () => logic.toNotice(),
                BorderRadius.only(
                  topLeft: Radius.circular(kRadiusSmall),
                  topRight: Radius.circular(kRadiusSmall),
                ),
              ),
              _buildItem(
                'assets/icons/ic_dis_case.png',
                '案件',
                () => logic.toCase(),
                null,
              ),
              _buildItem(
                'assets/icons/ic_dis_seal.png',
                '用印',
                () => logic.toSeal(),
                BorderRadius.only(
                  bottomLeft: Radius.circular(kRadiusSmall),
                  bottomRight: Radius.circular(kRadiusSmall),
                ),
              ),
            ],
          )),
          _buildCard(Column(
            children: [
              _buildItem('assets/icons/ic_dis_lichong.png',  '智能会议室',
                      () => logic.toMeetingRoomPage(), null),
              _buildItem('assets/icons/ic_ai.svg',  ' AI大师',
                      () => logic.toAIPage(), null),
              _buildItem(
                  'assets/icons/ic_dis_cloud.png', '知识管理', () => logic.toFolderList(), null),
              _buildItem(
                  'assets/icons/ic_dis_lichong.png',
                  '利冲查询',
                  () => logic.toCaseQuery(),
                  BorderRadius.only(
                    topLeft: Radius.circular(kRadiusSmall),
                    topRight: Radius.circular(kRadiusSmall),
                  )),
              _buildItem(
                  'assets/icons/ic_dis_search_law.png', '法律检索', () => logic.toWeiKe(), null),
              _buildItem('assets/icons/ic_dis_search_company.png',  '企业查询',
                      () => logic.toCompany(), null),
              // _buildItem(
              //     'assets/icons/ic_dis_law_calculator.png',
              //     '法律计算器',
              //     () => logic.toComputer(),
              //     BorderRadius.only(
              //       bottomRight: Radius.circular(kRadiusSmall),
              //       bottomLeft: Radius.circular(kRadiusSmall),
              //     )),
            ],
          )),
        ],
      ),
    );
  }

  Widget _buildCard(Widget child) {
    return Padding(
      padding: EdgeInsets.only(left: 10.w, right: 10.w, top: kSpaceSmall),
      child: Ink(
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(kRadiusSmall),
          ),
          child: child),
    );
  }

  Widget _buildItem(String iconPath, String title, void Function() onTap,
      BorderRadius? radius) {
    return InkWell(
      onTap: onTap,
      borderRadius: radius ?? BorderRadius.circular(0.w),
      child: Padding(
        padding: EdgeInsets.all(kSpaceSmall),
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            iconPath.endsWith('.svg')?
            SvgPicture.asset(
              'assets/icons/ic_ai.svg',
              width: kIconSizeTiny,
            ):
            Image.asset(
              iconPath,
              width: kIconSizeMini,
              height: kIconSizeMini,
            ),
            SizedBox(width: kSpaceMini),
            Expanded(
              child: Text(
                title,
                style: TextStyle(
                  color: AppColor.colorFontBlack,
                  fontSize: kFontSizeSmall,
                  fontWeight: AppFont.fontRegular,
                ),
              ),
            ),
            Icon(
              Icons.arrow_forward_ios,
              color: AppColor.colorFontGrey,
              size: 14.w,
            ),
          ],
        ),
      ),
    );
  }
}
